<?php

class Resource_Block_Hidden extends Resource_Block_Abstract 
{
    
    /**
    * Return navigation.
    * 
    * @return array
    */
    protected function _navigation() 
    {
        $entries = array();
        
        foreach ($this->_getResources() as $entry) {
            $entries[] = array(
                'id' => $entry['id'], 
                'active' => $entry['id'] == $this->_active(), 
                'backend_url' => array('id' => $entry['id']), 
                'name' => $entry['url'], 
                'children' => array(), 
                );
        }
        
        return $entries;
    }
    
    /**
    * Return active resource.
    * 
    * @return integer
    */
    protected function _active() 
    {
        if (Application::getRequest()->get('id')) {
            return (int)Application::getRequest()->get('id');
        } else {
            $entries = $this->_getResources();
            if (!empty($entries)) {
                return $entries[0]['id'];
            }
        }
    }
    
    private function _getResources() 
    {
        static $cach = array();
        
        if (empty($cahc)) {
            $query = '
                SELECT 
                       `id`, 
                       `url` 
                  FROM 
                       `system_resource` 
                 WHERE 
                       `id` NOT IN (SELECT DISTINCT `resource_id` FROM `system_navigation_item` )
                   AND 
                       -- do not shure whether these urls need meta accessories, blocks and other stuff
                       `url` NOT IN ("user", "confirm", "doc")
                ';
            
            $cach = database::fetchAll($query);
        }
        
        return $cach;
    }
    
}